<script setup lang="ts">
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { useAuthStore } from '#/store';

const router = useRouter();
const authStore = useAuthStore();

onMounted(async () => {
  const urlParams = new URLSearchParams(window.location.search);
  const code = urlParams.get('code');
  const state = urlParams.get('state');
  
  if (!code || !state) {
    // 如果没有code或state，重定向到登录页
    await router.push('/auth/login');
    return;
  }

  try {
    await authStore.handleOidcCallback(code);
  } catch (error) {
    console.error('OIDC callback error:', error);
    // 发生错误时重定向到登录页
    await router.push('/auth/login');
  }
});
</script>

<template>
  <div class="flex h-full w-full items-center justify-center">
    <div class="text-lg">处理登录中...</div>
  </div>
</template> 